# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libjpeg-turbo

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.1
pkgrel=3
pkgdesc="JPEG image codec with accelerated baseline compression and decompression (mingw-w64)"
arch=('any')
url="http://libjpeg-turbo.virtualgl.org"
license=("GPL, custom")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
groups=("${MINGW_PACKAGE_PREFIX}")
makedepends=("nasm" "${MINGW_PACKAGE_PREFIX}-gcc")
provides=("${MINGW_PACKAGE_PREFIX}-libjpeg")
conflicts=("${MINGW_PACKAGE_PREFIX}-libjpeg")
replaces=("${MINGW_PACKAGE_PREFIX}-libjpeg")
options=('staticlibs' 'strip')
source=("http://downloads.sourceforge.net/libjpeg-turbo/libjpeg-turbo-$pkgver.tar.gz"
        "libjpeg-turbo-match-autoconf-behavior.patch"
        "jpeg-7-tiff-ojpeg.patch"
        "jpeg-typedefs.patch"
        "libjpeg-buf-oflo.patch"
        "libjpeg-turbo-1.3.1-libmng-compatibility.patch")
md5sums=('2c3a68129dac443a72815ff5bb374b05'
         '6b00863ecdd729cb757e7f3672324f6f'
         '4f927780387c77244c2f89b2c6a66eb2'
         'b758ab3ac6a0604c6ed5fb9d850c9a73'
         '8835de1a830ae9979460f14f79e90630'
         'b54c2ab69837e1b72605184364360af0')

prepare() {
  cd "$srcdir/libjpeg-turbo-$pkgver"
  patch -p1 -i ${srcdir}/libjpeg-turbo-match-autoconf-behavior.patch
  patch -p1 -i ${srcdir}/jpeg-7-tiff-ojpeg.patch
  patch -p1 -i ${srcdir}/jpeg-typedefs.patch
  patch -p1 -i ${srcdir}/libjpeg-buf-oflo.patch
  patch -p1 -i ${srcdir}/libjpeg-turbo-1.3.1-libmng-compatibility.patch
}

build() {
  mkdir -p "${srcdir}/build-${CARCH}"
  cd "${srcdir}/build-${CARCH}"
  "${srcdir}"/${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-jpeg8 \
    --mandir=${MINGW_PREFIX}/share/man
  make
}

package() {
  cd "${srcdir}/build-${CARCH}"
  make DESTDIR="$pkgdir" install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
  cp "${srcdir}"/${_realname}-${pkgver}/{jinclude,transupp}.h ${pkgdir}${MINGW_PREFIX}/include/
}
